﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Xml;

namespace BuildProject
{
    public class sdfsdfsdf
    {
        public static XmlDocument LoadXMLFile(string filename)
        {
            XmlDocument doc = new XmlDocument();
            doc.Load(filename);

            List<XmlNode> xmlList = GetNodeByName(doc.DocumentElement, "ItemGroup");
            foreach (XmlNode node in xmlList)
            {
                List<XmlNode> childs = new List<XmlNode>();
                foreach (XmlNode x in node.ChildNodes)
                    childs.Add(x);

                foreach (XmlNode childNode in childs)
                {
                    if (childNode.Name == "ClInclude" || childNode.Name == "ClCompile")
                    {
                        node.RemoveChild(childNode);
                    }
                }

                if (node.ChildNodes.Count == 0)
                    doc.DocumentElement.RemoveChild(node);
            }

            return doc;
        }

        public static List<XmlNode> GetNodeByName(XmlNode root, string name)
        {
            List<XmlNode> xmlList = new List<XmlNode>();
            foreach (XmlNode node in root.ChildNodes)
            {
                if (node.LocalName == name)
                    xmlList.Add(node);
            }

            return xmlList;
        }
    }
}
